#!/usr/bin/env python
# -*- coding:utf-8 -*- 
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:

"""
@version: 1.0
@author: readerror
@contact: readerror@readerror.cn
@contact1: readerror000@gmail.com
@site: http://www.readerror.cn
@software: PyCharm
@file: ge.py
@time: 2017/3/15 9:20
"""


data = \
    {"org.zstack.header.vm.APIQueryVmNicMsg": {"session": {"uuid": "f65ac744640744a49d8b78f0e7364641"},
                                               "conditions": []}}
if __name__ == '__main__':
    for k, v in data.items():
        name = k.split('.API')[1].split('Msg')[0]
        name_lower = name.lower()
        func_name = ''
        for i, ch in enumerate(name_lower):
            if ch != name[i]:
                func_name += '_'
            func_name += ch
        func_name = func_name[1:]

        if func_name[:5] == 'query':
            print('''
def {0}(self, data=None, async=False):
    """
    {1}
    :param async: Can be used to asynchronously execute code.
    :param data:'''.format(func_name, name))

            __import__('pprint').pprint(v)

            print('''    """
    if data is None:
        data = {}
    if data.get('conditions') is None:
        data['conditions'] = []
    rsp = self.api_call("%s", data, async=async)
    return self.get_api_result(rsp)
        ''' % k)

        else:
            print('''
def {0}(self, data, async=False):
    """
    {1}
    :param async: Can be used to asynchronously execute code.
    :param data:'''.format(func_name, name))

            __import__('pprint').pprint(v)

            print('''    """
    rsp = self.api_call("{1}", data, async=async)
    return self.get_api_result(rsp)
        '''.format(name, k))
